import { Injectable } from '@nestjs/common'
import { InjectRepository } from '@nestjs/typeorm'
import { Repository } from 'typeorm'
import { CreateQrCodeDto, FindQrCodeDto, UpdateQrCodeDto } from './dto/qr-code.dto'
import { QrCode } from './entities/qr-code.entity'

@Injectable()
export class QrCodeService {
  constructor(
    @InjectRepository(QrCode)
    private qrCodeRepository: Repository<QrCode>,
  ) {}

  create(createData: CreateQrCodeDto) {
    return this.qrCodeRepository.save(createData)
  }

  async findOne(data: FindQrCodeDto) {
    return await this.qrCodeRepository.findOneBy(data)
  }

  async findList(data: FindQrCodeDto) {
    return await this.qrCodeRepository.find({
      where: data,
    })
  }

  async update(qrCodeId: number, updateData: UpdateQrCodeDto) {
    return this.qrCodeRepository.update(qrCodeId, {
      ...updateData,
      qrCodeId: undefined,
    })
  }

  remove(qrCodeId: number) {
    return this.qrCodeRepository.delete(qrCodeId)
  }
}
